﻿$.ajaxSetup({ url: "Proxy.ashx", type: "post", dataType: "json" });

function btnSave_Click() {
    var id = QueryString("id");
    var cityId = $("#ddl_City").val();
    var areaId = $("#ddl_Area").val();
    var streetId = $("#ddl_Street").val();
    var name = $("#txtName").val();     // 车位名称
    var sensorCode = $("#txtSensorCode").val();     // 泊位传感器编号
    var connection = $("#txtConnection").val();     // 连接方式
    var berthModel = $("#ddl_BerthModel").val();     // 泊位车型
    var berthType = $("#ddl_BerthType").val();     // 泊位类型
    var restriction = $("#ddl_Restriction").val();     // 停车限制条件
    var feeRule = $("#ddl_FeeRule").val();     // 收费规则
    var continuousLong = $("#ddl_ContinuousLong").val();     // 连续时长校费规则
    var longitude = $("#txtLongitude").val();     // 经度
    var latitude = $("#txtLatitude").val();     // 纬度

    $.ajax({
        data: { method: "UpdateParkingSpace", id:id,cityId: cityId, areaId: areaId, streetId: streetId, name: name, sensorCode: sensorCode, connection: connection, berthModel: berthModel, berthType: berthType, restriction: restriction, feeRule: feeRule, continuousLong: continuousLong, longitude: longitude, latitude: latitude }
        , success: function (json) {
            var msg = "";
            if (json.isSuccess == "true") {
                msg = "数据修改成功！"
            }
            else {
                msg = "数据修改失败，请重试..."
            }
            alert(msg);
        }
    });
}

function InitBerthModel(id) {
    $.ajax({
        data: { method: "ListBerthModels" }
        , success: function (json) {
            $("#ddl_BerthModel").append("#full_BerthModel", json.BerthModels);
            $("#ddl_BerthModel ").val(id); 
        }
    });
}

function InitBerthType(id) {
    $.ajax({
        data: { method: "ListBerthType" }
        , success: function (json) {
            $("#ddl_BerthType").append("#full_BerthType", json.BerthType);
            $("#ddl_BerthType ").val(id); 
        }
    });
}

function InitRestrictions(id) {
    $.ajax({
        data: { method: "ListRestrictions" }
        , success: function (json) {
            $("#ddl_Restriction").append("#full_Restriction", json.Restrictions);
            $("#ddl_Restriction ").val(id); 
        }
    });
}

function InitFeeRules(id) {
    $.ajax({
        data: { method: "ListFeeRules" }
        , success: function (json) {
            $("#ddl_FeeRule").append("#full_FeeRule", json.FeeRules);
            $("#ddl_FeeRule ").val(id); 
        }
    });
}

function InitContinuousLong(id) {
    $.ajax({
        data: { method: "ListContinuousLong" }
        , success: function (json) {
            $("#ddl_ContinuousLong").append("#full_ContinuousLong", json.ContinuousLong);
            $("#ddl_ContinuousLong ").val(id); 
        }
    });
}

function InitParkingSpaceInfo() {
    var id = QueryString("id");
    if (id != null && id != undefined) {
        $.ajax({
            data: { method: "GetParkingSpaceInfoById", id: id }
        , success: function (json) {
            BindCity(json.ParkingSpaceInfo.CityId, json.ParkingSpaceInfo.AreaId, json.ParkingSpaceInfo.StreetId);
            InitBerthModel(json.ParkingSpaceInfo.BerthModelId);
            InitBerthType(json.ParkingSpaceInfo.BerthTypeId);
            InitRestrictions(json.ParkingSpaceInfo.RestrictionId);
            InitFeeRules(json.ParkingSpaceInfo.FeeRuleId);
            InitContinuousLong(json.ParkingSpaceInfo.ContinuousLongId);

            $("#txtName").val(json.ParkingSpaceInfo.Name);     // 车位名称
            var sensorCode = $("#txtSensorCode").val(json.ParkingSpaceInfo.SensorNo);     // 泊位传感器编号
            var connection = $("#txtConnection").val(json.ParkingSpaceInfo.Connection);     // 连接方式
            var longitude = $("#txtLongitude").val(json.ParkingSpaceInfo.Longitude);     // 经度
            var latitude = $("#txtLatitude").val(json.ParkingSpaceInfo.Latitude);     // 纬度
        }
        });
    }
}

function init() {
    InitParkingSpaceInfo();
    $("#btnSave").click(function () {
        btnSave_Click();
    });
}